﻿using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;


namespace Sugata.SolutionFoldersOrganizer
{

    [ProvideMenuResource(1000, 1)] // the resource id, set in the VSCT compiler in the project file
    [PackageRegistration(UseManagedResourcesOnly = true)]
    [Guid("05BAD736-00C5-463C-B29C-D38535ABBF0B")]
    [InstalledProductRegistration("Solution folders organizer", "Sync solution folders with filesystem structure", "1.0")] //IconResourceID = 400
    [ComVisible(true)]
    partial class SolutionFoldersOrganizerPackage : Package
    {

        public static readonly Guid PackageGuid = new Guid("{05BAD736-00C5-463C-B29C-D38535ABBF0B}");
        public static readonly Guid CommandSetGuid = new Guid("{A11EE497-1262-4E84-AE83-C08824CA0639}");
        public static readonly Guid BitmapGuid = new Guid("{67811AE5-5D68-4507-B59E-B7E9FBE07627}");
        public const int OrganizeCommandId = 0x2003;
        
        public static void SolutionFoldersOrganizer()
        {
            //Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "ASDA Entering constructor for: {0}", this.ToString()));
        }

        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        protected override void Initialize()
        {
            
            Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Initialize() of: {0}", this.ToString()));

            base.Initialize();

            var menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (menuCommandService == null) throw new ApplicationException("Unable to instantiate menuCommandService");

            var commandId = new CommandID(CommandSetGuid, OrganizeCommandId);
            var command = new OleMenuCommand(new EventHandler(OrganizeSolutionFolders), commandId);
            
            menuCommandService.AddCommand(command);

        }

    }
}
